.org 0xE60D0 ; Fuel Consumption

Fuel_Consumption:

	PUSH 	{R4-R7, LR}
	
	SUB  	SP, SP, 4
	
	LDR 	R4, [Fuel_Consumption_1]
	LDR 	R3, [Fuel_Consumption_2]	
	LDR 	R5, [R4, 0]
	LDR 	R4, [R3, 0]
	
	MOV 	R3, 0x98	
	
	ADD 	R4, R5, R4, LSL 2
	LDR		R5, [R4, 0x48]
	MUL		R4, R0, R3
	ADD 	R0, R5, 0x5000
	LDR 	R0, [R0, 0xA58]
	MOV		R7, R1
	ADD 	R0, R0, R4
	ADD 	R0, R0, 0x74
	
	MOV 	R1, CO_Air_Fuel						; Skill: -2 fuel consumption for Air Units
	
	MOV		R6, R2
	MOV		R5, 0
	
	BL 		Check_Skills_Equipped				; Check the Skill is equipped
	
	CMP 	R0, 0								; Does CO use that skill?
	BEQ		No_Fuel_Air_Saver
	
	MOV		R0, 0x6C
	MUL		R1, R7, R0
	LDR		R0, [Fuel_Consumption_3]
	LDRB	R0, [R0, R1]
	
	ADD		R0, R0, 0xFD
	AND		R0, R0, 0xFF
	
	CMP		R0, 1								; 
	ADDLS	R5, R5, 2							; If CO use skill, -2 fuel consumption for air units
	
;-------------------------------------------------------------------------------
	
No_Fuel_Air_Saver:

	CMP 	R6, 0								; Can unit Dive/Hide?							
	BEQ		Unit_No_Dive_Hide					; If not, skip code
	
	LDR 	R1, [Fuel_Consumption_1]
	LDR 	R0, [Fuel_Consumption_2]	
	LDR 	R2, [R1, 0]
	LDR 	R0, [R0, 0]
	
	MOV 	R1, Rank_Sneaky						; Rank: Sneaky
	
	ADD 	R0, R2, R0, LSL 2
	LDR		R0, [R0, 0x48]
	
	ADD 	R0, R0, 0x5000
	LDR 	R0, [R0, 0xA58]
	ADD 	R0, R0, R4
	ADD 	R0, R0, 0x74
	
	BL 		Check_Skills_Equipped				; Check the Skill is equipped
	
	CMP 	R0, 0								; Does CO use that skill?
	
	LDR 	R1, [Fuel_Consumption_1]
	LDR 	R0, [Fuel_Consumption_2]	
	LDR 	R2, [R1, 0]
	LDR 	R0, [R0, 0]
	
	MOV 	R1, Rank_Stealthy					; Rank: Stealthy
	
	ADD 	R0, R2, R0, LSL 2
	LDR		R0, [R0, 0x48]
	
	ADDNE	R5, R5, 1							; If CO use skill, -1 fuel consumption when dived/hidden
	
	ADD 	R0, R0, 0x5000
	LDR 	R0, [R0, 0xA58]
	ADD 	R0, R0, R4
	ADD 	R0, R0, 0x74
	
	BL 		Check_Skills_Equipped				; Check the Skill is equipped
	
	CMP 	R0, 0								; Does CO use that skill?
	
	ADDNE	R5, R5, 2							; If CO use skill, -2 fuel consumption when dived/hidden
	
;-------------------------------------------------------------------------------	
	
Unit_No_Dive_Hide:

	MOV		R0, R5
	
	ADD  	SP, SP, 4
	
	POP 	{R4-R7, LR}	
	BX 		LR

;-------------------------------------------------------------------------------		

Fuel_Consumption_1:
	.dw Reg1_Skill
	
Fuel_Consumption_2:
	.dw Reg2_Skill
	
Fuel_Consumption_3:
	.dw 0x022F4FD4



